<?php


namespace app\admin\model\Free;


use think\facade\Db;
use think\Model;

class FreeOrderModel extends Model
{

    /**
     * 数据表名
     * @var string
     */
    protected $name = "free_order";

    /**
     * 根据条件查询单条数据
     * @param $where
     * @param string $field
     * @return mixed
     * @throws
     */
    public static function getFreeOrderWhere($where,$field="*")
    {
        $goods = Db::name("free_order")->field($field)->where($where)->find();
        return $goods;
    }

    /**
     * 根据条件查询多条数据
     * @param $where
     * @return mixed
     * @throws
     */
    public static function getFreeOrderWhereMore($where,$filed="*")
    {
        $list = Db::name("free_order")->field($filed)->where($where)->order('add_time desc')->select()->toArray();
        return $list;
    }

    /**
     * 统计总数
     * @param $where
     * @return int
     */
    public static function getFreeOrderCountWhere($where)
    {
        $count = Db::name("free_order")->where($where)->count();
        return $count;
    }

    /**
     * 分页查询
     * @param $page
     * @param $limit
     * @param array $where
     * @param int $sort
     * @param string $field
     * @return array
     * @throws
     */
    public static function getFreeOrderListWhere($page,$limit,$where = [],$field="*")
    {
        $start = ceil(($page-1)*$limit);
        $list = Db::name('free_order')
            ->field($field)
            ->where($where)->limit($start,$limit)->order('add_time desc')->select()->toArray();
        return $list;
    }

    /**
     * 添加
     * @param $data
     * @return int|string
     */
    public static function addFreeOrder($data)
    {
        $id = Db::name('free_order')->insertGetId($data);
        return $id;
    }

    /**
     * 编辑
     * @param $where
     * @param $save
     * @return int
     */
    public static function updateFreeOrder($where,$save)
    {
        $flag = Db::name('free_order')->where($where)->save($save);
        return $flag;
    }

}